<?php 

namespace app\api\model;

use think\Model;
use think\Db;
class User extends Model{
	/**
	* 获得用户推荐码
	* 2018.03.02
	* BY HF
	*/
	public function get_user_refer($id){
		$code=(int)$id+1000;
		return $code;
	}
	/** 
	* 获得推荐者ID 
	* @param refer 推荐码
	* 2018.03.02
	* BY HF
	* @return pid 推荐者的ID或者0
	*/
	public function get_refer_id($refer){
		if($refer){
			return $this->where(['isdelete'=>0,'refer'=>$refer])->value('id')?:0;
		}else{
			return 0;	
		}
	}

	/**
	* 获得用户openid
	* @param id 用户ID
	* 2018.03.03
	* BY HF
	*/
	public function get_openid($id){
		if($id == false){
			return ['code'=>400,'message'=>'缺少必要的参数ID'];
		}

		$openid=$this->where('id',$id)->value('openid');

		return $openid;
	}
	
	/** 
	* 获得用户昵称和头像
	* @param id 用户ID
	* 2018.03.03
	* BY HF 
	*/
	public function get_head_nick($id){
		return Db::table('tp_user')->alias('u')
							->join('img i','i.relation_id=u.id and i.isdelete=0 and i.folder=\'headimg\'','LEFT')
							->where(['u.id'=>$id])
							->field('u.nickname,i.url')
							->find();
	}

	/**
	* 获得用户认证状态
	* @param id 用户ID
	* 2018.03.08
	* BY HF
	*/
	public function get_audit_status($id){
		return $this->where('id',$id)->value('audit_status');
	}

}


 ?>